<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App\Models\Picture;
class CommentPicture extends Model
{
    /**
     * 表名称
     * @var $table;
     */
    protected $table = 'comment_picture';

    /**
     * 主键
     * @var $primaryKey
     */
    protected $primaryKey = 'goods_id';

    /**
     * 时间戳   laravel ORM 自动维护数据库时间戳,用户数据结构的回滚操作,默认开启,我们禁止
     * @var bool $timestamps
     */
    public $timestamps = false;
    protected $appends = array('mobile_pic_1','mobile_pic_2','mobile_pic_3','mobile_pic_4');
    /**
     * 自动填充字段
     * @var $fillable
     */
    protected $fillable = ['goods_id', 'pic_1', 'pic_2','pic_3','pic_4'];

    function getMobilePic1Attribute(){

        $pic_1 = $this->getAttribute('pic_1');
        if(!$pic_1){
            return null;
        }

        return Picture::find($pic_1)->url;

    }
    function getMobilePic2Attribute(){

        $pic_2 = $this->getAttribute('pic_2');
        if(!$pic_2){
            return null;
        }

        return Picture::find($pic_2)->url;

    }
    function getMobilePic3Attribute(){

        $pic_3 = $this->getAttribute('pic_3');
        if(!$pic_3){
            return null;
        }

        return Picture::find($pic_3)->url;

    }
    function getMobilePic4Attribute(){

        $pic_4 = $this->getAttribute('pic_4');
        if(!$pic_4){
            return null;
        }

        return Picture::find($pic_4)->url;

    }






}
